/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webidewar.system;

import com.icesoft.faces.async.render.OnDemandRenderer;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author huy
 */
public class AjaxOutputStream extends OutputStream {

    private inout io;
    private OnDemandRenderer renderer;

    public inout getIo() {
        return io;
    }

    public void setIo(inout io) {
        this.io = io;
    }

    public AjaxOutputStream(inout _io, OnDemandRenderer _renderer) {
        super();
        setIo(_io);
        renderer = _renderer;
    }

    @Override
    public void write(int b) throws IOException {
        //Logger.getLogger(AjaxOutputStream.class.getName()).log(Level.SEVERE, null, "*******************************************");
        //System.out.println(getIo().getOutput());
        getIo().putOutputByte(b);
        //getIo().setOutput("sssssssssss");
        renderer.requestRender();
    //try {
    //    Thread.sleep(100);
    //throw new UnsupportedOperationException("Not supported yet.");
    //} catch (InterruptedException ex) {
    //    Logger.getLogger(AjaxOutputStream.class.getName()).log(Level.SEVERE, null, ex);
    //}
    //throw new UnsupportedOperationException("Not supported yet.");
    }
}
